﻿using DeviceCommons.DataHandling;
using DeviceCommons.DeviceMessages.Abstractions;
using DeviceCommons.DeviceMessages.Models.V1;
using System.Buffers;

namespace DeviceCommons.DeviceMessages.Serialization.V2.Serializers
{
    public class DeviceMessageInfoSerializer : AbstractMessageSerializer<IDeviceMessageInfo>, IDeviceMessageInfoSerializer
    {
        public DeviceMessageInfoSerializer() : base(new DeviceMessageInfo())
        {
        }

        public override void Serializer(ArrayBufferWriter<byte> writer, IDeviceMessageInfo message)
        {
            ArgumentNullException.ThrowIfNull(message);
            ArgumentNullException.ThrowIfNull(message.Reading);
            writer.Write([message.Length]);
            writer.Write(message.DIDBytes);
            writer.Write([message.DeviceType]);
            DeviceMessageSerializerProvider.InfoReadingsV2Ser.Serializer(writer, message.Reading);
        }
    }
}
